package com.cqut.controller;


import com.cqut.VO.discuss.DiscussContentVO;
import com.cqut.VO.result.ResultVO;
import com.cqut.entity.Discuss;
import com.cqut.mapper.DiscussMapper;
import com.cqut.service.DiscussService;
import com.cqut.util.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 冯永龙
 * @since 2021-06-15
 */
@RestController
@RequestMapping("//discuss")
public class DiscussController {

    @Autowired
    private DiscussService discussService;

    @PutMapping("/addDiscuss")
    public ResultVO<Object> addDiscuss(@RequestBody Discuss discuss) {
        if (discussService.insertDiscuss(discuss)) {
            return ResultVOUtil.success(null);
        }
        return ResultVOUtil.fail();
    }

    @DeleteMapping("/deleteDiscuss/{discussId}")
    public ResultVO<Object> deleteDiscuss(@PathVariable("discussId") Integer discussId) {
        if (discussService.deleteDiscuss(discussId)) {
            return ResultVOUtil.success(null);
        }
        return ResultVOUtil.fail();
    }

    @GetMapping("/getContent/{topicId}")
    public ResultVO<List<DiscussContentVO>> getContent(@PathVariable("topicId") Integer topicId) {
        List<DiscussContentVO> contentList = discussService.getContentList(topicId);
        if (contentList != null) {
            return ResultVOUtil.success(contentList);
        }
        return ResultVOUtil.fail();
    }

    @GetMapping("/getContentNumber/{topicId}")
    public ResultVO<Integer> getTotalContentNumber(@PathVariable("topicId") Integer topicId) {
        if (topicId != null) {
            return ResultVOUtil.success(discussService.getTotalContentNumber(topicId));
        }
        return ResultVOUtil.fail();

    }

}

